// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// import tinymce from 'tinymce/tinymce'
// import 'tinymce/themes/silver/theme'
// import Editor from '@tinymce/tinymce-vue'
// import '../static/UE/ueditor.config'
// import '../static/UE/ueditor.all'
// import '../static/UE/lang/zh-cn/zh-cn'
// import '../static/UE/ueditor.parse'
// import moment from 'moment'

// Vue.filter('dateformat', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
//     return moment(dataStr).format(pattern)
// })
// import SIdentify from './components/page/identify'
// Vue.use(SIdentify)
import './style/theme.css'
import './style/characters.css'
import './style/icon.css'
import './assets/icon/iconfont.css';
// Vue.use(require('moment'));
Vue.use(ElementUI)
Vue.config.productionTip = false


// 注册一个全局守卫，作用是在路由跳转前，对路由进行判断，防止未登录的用户跳转到其他需要登录的页面去
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('mytoken')
  var time = localStorage.getItem('time')
  var guoqi =  Date.parse(new Date())
  // 设置过期时间
  var shijian = 1000*60*60*24
  console.log(guoqi-time)
  console.log(shijian)
  var timeguoqi = guoqi - time
  console.log(timeguoqi>shijian)
  if(timeguoqi>shijian){
    // next({path: '/login'})
    if (to.path !== '/login') {
      // 如果没有登录，但你访问其他需要登录的页面，那我就让你跳到登录页面去
      next({path: '/login'})
    } else {
      // 如果没有登录，但你访问的login，那就不干涉你，让你访问
      next()
    }
  }else{
  }
  // 如果已经登录，那我不干涉你，让你随便访问
  // console.log(token)
  if (token) {
    next()
  } else {
    if (to.path !== '/login') {
      // 如果没有登录，但你访问其他需要登录的页面，那我就让你跳到登录页面去
      next({path: '/login'})
    } else {
      // 如果没有登录，但你访问的login，那就不干涉你，让你访问
      next()
    }
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
